#include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n,mod; 
inline int ksm(int a,int b){
	int res=1;
	while(b>0){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}int fac[N],inv[N];
inline int C(int n,int m){
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int dp[3005][3005];
signed main(){
	freopen("tree.in","r",stdin);
	freopen("tree.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read(),mod=read();
	if(n==1){
		puts("1");
		return 0;
	}
	int p=1;
	fac[0]=1;
	inv[0]=1;
	For(i,1,n) fac[i]=fac[i-1]*i%mod;
	inv[n]=ksm(fac[n],mod-2);
	Rof(i,n-1,1) inv[i]=inv[i+1]*(i+1)%mod;
	int ans=0;
	dp[0][0]=1;
	For(i,1,n){
		For(j,0,n){
			if(!dp[i-1][j]) continue; 
			For(t,1,n-j){	
				dp[i][j+t]+=(dp[i-1][j]*C(j+t,j)%mod*ksm(t,t-1)%mod);
				dp[i][j+t]%=mod;
			}
		}
	} 
	ans=0;
	For(i,1,n){
		ans+=dp[i][n]*ksm(2,n-i)%mod;
		ans%=mod;
	}
	printf("%lld\n",ans);
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

